package cn.edu.ctbu.sbadmin.grade.dao;

import cn.edu.ctbu.sbadmin.common.core.MyMapper;

import cn.edu.ctbu.sbadmin.grade.domain.SubjectDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;


/**
 * <p>
 * 教师表 Mapper 接口
 * </p>
 *
 * @since 2022-05-08
 */
public interface SubjectDao extends MyMapper<SubjectDO> {


    @Select("SELECT\n" +
            "`subject`.id,\n" +
            "`subject`.teacher_id,\n" +
            "`subject`.th_num,\n" +
            "`subject`.subject_name,\n" +
            "`subject`.profession_type,\n" +
            "`subject`.subject_type,\n" +
            "`subject`.subject_from,\n" +
            "`subject`.Introduction,\n" +
            "`subject`.base_req,\n" +
            "`subject`.`references`,\n" +
            "`subject`.delete_userid,\n" +
            "`subject`.second_tutor,\n" +
            "`subject`.student_id,\n" +
            "`subject`.select_type,\n" +
            "`subject`.is_deleted,\n" +
            "`subject`.audit_opinion,\n" +
            "`subject`.gmt_modified,\n" +
            "`subject`.gmt_create,\n" +
            "`subject`.audit_state,\n" +
            "`subject`.audit_description,\n" +
            "teacher.t_no as tno,\n" +
            "teacher.`name` AS teacher_name,\n" +
            "student.s_no as sno,\n" +
            "student.`name` AS student_name,\n" +
            "dim_aud_states.state_name\n" +
            "FROM\n" +
            "`subject`\n" +
            "INNER JOIN teacher ON teacher.id = `subject`.teacher_id\n" +
            "LEFT JOIN student ON student.id = `subject`.student_id\n" +
            "INNER JOIN dim_aud_states ON dim_aud_states.`value` = `subject`.audit_state \n  "+
            "${ew.customSqlSegment}")
    IPage<SubjectDO> selectPage(IPage<SubjectDO> page,
                                @Param(Constants.WRAPPER) QueryWrapper<SubjectDO> queryWrapper);

    /*.**
    * @Description: 使用MybatisPlus来对于subject表做查询
    * @Param: queryWrapper
    * @Return: List<SubjectDO>
    * @Author: HighJ
    */
    @Select("SELECT\n" +
            "`subject`.id,\n" +
            "`subject`.teacher_id,\n" +
            "`subject`.th_num,\n" +
            "`subject`.subject_name,\n" +
            "`subject`.profession_type,\n" +
            "`subject`.subject_type,\n" +
            "`subject`.subject_from,\n" +
            "`subject`.Introduction,\n" +
            "`subject`.base_req,\n" +
            "`subject`.`references`,\n" +
            "`subject`.delete_userid,\n" +
            "`subject`.second_tutor,\n" +
            "`subject`.student_id,\n" +
            "`subject`.select_type,\n" +
            "`subject`.is_deleted,\n" +
            "`subject`.audit_opinion,\n" +
            "`subject`.gmt_modified,\n" +
            "`subject`.gmt_create,\n" +
            "`subject`.audit_state,\n" +
            "`subject`.audit_description,\n" +
            "teacher.t_no as tno,\n" +
            "teacher.`name` AS teacher_name,\n" +
            "student.s_no as sno,\n" +
            "student.`name` AS student_name,\n" +
            "dim_aud_states.state_name\n" +
            "FROM\n" +
            "`subject`\n" +
            "INNER JOIN teacher ON teacher.id = `subject`.teacher_id\n" +
            "LEFT JOIN student ON student.id = `subject`.student_id\n" +
            "INNER JOIN dim_aud_states ON dim_aud_states.`value` = `subject`.audit_state \n  "+
            "${ew.customSqlSegment}")
    List<SubjectDO> getNullSubject(@Param(Constants.WRAPPER) QueryWrapper<SubjectDO> queryWrapper);
}